package Program;

import java.util.Random;
import java.util.Scanner;

public class Case4
{
    public static void main(String[] args) {
        //双色球案例
        int[] UserNumber = User();
        int[] SystemNumber = CreatNumber();
        print(UserNumber);
        System.out.println();
        print(SystemNumber);
        System.out.println();
        judge(UserNumber,SystemNumber);
    }


    //输出号码
    public static void print(int[] Number)
    {
        for (int i = 0; i < Number.length; i++) {
            System.out.print(i<Number.length-1?Number[i] + ",":Number[i]);

        }
    }
    //用户输入
    public static int[] User()
    {
        int[] Number = new int[7];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < Number.length - 1; i++)
        {
            while (true)
            {
                System.out.println("请输入1~33之间的数字" + "第" + (i+1) + "个红球号码");
                int number = sc.nextInt();
                if(number<1 || number>33)
                {
                    System.out.println("该数字不在1~33区间，请重新输入");
                }
                else
                {
                    if(exist(Number,number))
                    {
                        System.out.println("对不起该球已在前面选择过了，请重新输入");
                    }
                    else
                    {
                        Number[i] = number;
                        break;
                    }
                }
            }
        }

        System.out.println("请输入1~16之间的蓝球号码");
        while (true)
        {
            int number = sc.nextInt();
            if(number>16 || number<1)
            {
                System.out.println("该数字不在1~16区间，请重新输入");
            }
            else
            {
                Number[6] = number;
                break;
            }

        }
        return Number;
    }
    //判断号码是否相同
    public static boolean exist(int[] numbers,int number)
    {
        for (int i = 0; i < numbers.length; i++)
        {
            if(numbers[i] == number)
            {
                return true;
            }

        }
        return false;
    }
    //系统创建一组数
    public static int[] CreatNumber()
    {
        Random r = new Random();
        int[] Number = new int[7];
        for(int i = 0; i < Number.length - 1; i++)
        {
            while (true)
            {
                int number = r.nextInt(33) + 1;
                if(!exist(Number,number))
                {
                    Number[i] = number;
                    break;
                }
            }
        }
        Number[6] = r.nextInt(16) + 1;
        return Number;
    }
    //判断是否中奖
    public static void judge(int[] UserNumber,int[] SystemNumber)
    {
        int redcount = 0;
        int bluecount = 0;
        //判断红球相等数量
        for(int i = 0; i < UserNumber.length - 1; i++)
        {
            if(UserNumber[i] == SystemNumber[i])
            {
                redcount++;
            }
        }
        if(UserNumber[6] == SystemNumber[6])
        {
            bluecount++;
        }
        if(bluecount != 0)
        {
            switch (redcount)
            {
                case 6:
                    System.out.println("恭喜您中了1000万");
                case 5:
                    System.out.println("恭喜您中了3000元");
                case 4:
                    System.out.println("恭喜您中了200元");
                case 3:
                    System.out.println("恭喜您中了10元");
                default:
                    System.out.println("恭喜您中了5元");
            }
        }
        else
        {
            switch (redcount)
            {
                case 6:
                    System.out.println("恭喜您中了500万");
                case 5:
                    System.out.println("恭喜您中了200元");
                case 4:
                    System.out.println("恭喜您中了10元");
                default:
                    System.out.println("很遗憾您没有中奖");
            }
        }
    }
}
